package com.xjy.web.controller.system;

import java.util.List;
import java.util.Arrays;

import com.xjy.system.domain.bo.*;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.annotation.Log;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.enums.BusinessType;
import com.xjy.system.domain.vo.SysReimbursementVo;
import com.xjy.system.service.ISysReimbursementService;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 费用报销信息Controller
 *
 * @author xjy
 * @date 2022-02-10
 */
@Api(value = "费用报销信息控制器", tags = {"费用报销信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/reimbursement")
public class SysReimbursementController extends BaseController {

    private final ISysReimbursementService iSysReimbursementService;

    /**
     * 查询费用报销信息列表
     */
    @ApiOperation("查询费用报销信息列表")
    @PreAuthorize("@ss.hasPermi('system:reimbursement:list')")
    @GetMapping("/list")
    public TableDataInfo<SysReimbursementVo> list(@Validated SysReimbursementQueryBo bo) {
        return iSysReimbursementService.queryPageList(bo);
    }

    /**
     * 导出费用报销信息列表
     */
    @ApiOperation("导出费用报销信息列表")
    @PreAuthorize("@ss.hasPermi('system:reimbursement:export')")
    @Log(title = "费用报销信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<SysReimbursementVo> export(@Validated SysReimbursementQueryBo bo) {
        List<SysReimbursementVo> list = iSysReimbursementService.queryList(bo);
        ExcelUtil<SysReimbursementVo> util = new ExcelUtil<SysReimbursementVo>(SysReimbursementVo.class);
        return util.exportExcel(list, "费用报销信息");
    }

    /**
     * 获取费用报销信息详细信息
     */
    @ApiOperation("获取费用报销信息详细信息")
    @PreAuthorize("@ss.hasPermi('system:reimbursement:query')")
    @GetMapping("/{id}")
    public AjaxResult<SysReimbursementVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iSysReimbursementService.queryById(id));
    }

    /**
     * 新增费用报销信息
     */
    @ApiOperation("新增费用报销信息")
    @PreAuthorize("@ss.hasPermi('system:reimbursement:add')")
    @Log(title = "费用报销信息", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody SysReimbursementChargeBo bo) {
        return toAjax(iSysReimbursementService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改费用报销信息
     */
    @ApiOperation("修改费用报销信息")
    @PreAuthorize("@ss.hasPermi('system:reimbursement:edit')")
    @Log(title = "费用报销信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping("/edit")
    public AjaxResult<Void> edit(@Validated @RequestBody SysReimbursementChargeBo bo) {
        return toAjax(iSysReimbursementService.updateByEditBo(bo) ? 1 : 0);
    }

	/**
	 * 修改费用报销信息
	 */
	@ApiOperation("修改费用报销信息")
	@PreAuthorize("@ss.hasPermi('system:reimbursement:edit')")
	@Log(title = "费用报销信息", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping("/audit")
	public synchronized AjaxResult<Void> audit(@Validated @RequestBody BaseAuditBo bo) {
		return toAjax(iSysReimbursementService.audit(bo) ? 1 : 0);
	}


	/**
     * 删除费用报销信息
     */
    @ApiOperation("删除费用报销信息")
    @PreAuthorize("@ss.hasPermi('system:reimbursement:remove')")
    @Log(title = "费用报销信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iSysReimbursementService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
